import React from "react"

import http from "../helper/request"

const useApi = () => {
	const { useState } = React
	const [loading, setLoading] = useState(false)

	async function generalHttp<T>(url: string, body: object | undefined) {
		setLoading(true)
		const ret = await http.post<T>(url, body)
		setLoading(false)
		return ret
	}
	const roleManageList = async (body: object | undefined) => {
		const ret = await generalHttp("/system/role/queryRoleList", body)
		return ret
	}

	const updateRoleManage = async (body: object | undefined) => {
		const ret = await generalHttp("/system/role/update", body)
		return ret
	}
	const addRoleManage = async (body: object | undefined) => {
		const ret = await generalHttp("/system/role/add", body)
		return ret
	}
	const deleteRoleManage = async (body: object | undefined) => {
		const ret = await generalHttp("/system/role/delete", body)
		return ret
	}
	const getQueryPermissionList = async (body: object | undefined) => {
		const ret = await generalHttp("/system/role/queryPermissionList", body)
		return ret
	}
	const getRolePermissionListAPI = async (body: object | undefined) => {
		const ret = await generalHttp("/system/role/permissions/list", body)
		return ret
	}
	const staffManageList = async (body: object | undefined) => {
		const ret = await generalHttp("/system/user/query4Page", body)
		return ret
	}

	const updateStaffManage = async (body: object | undefined) => {
		const ret = await generalHttp("/system/user/updateUserInfo", body)
		return ret
	}
	const addStaffManage = async (body: object | undefined) => {
		const ret = await generalHttp("/system/user/add", body)
		return ret
	}
	const deleteStaffManage = async (body: object | undefined) => {
		const ret = await generalHttp("/system/user/deleteUser", body)
		return ret
	}
	const queryRoleList = async (body: object | undefined) => {
		const ret = await generalHttp("/system/role/queryRoleList", body)
		return ret
	}
	const getGoogleAuth = async (body: object | undefined) => {
		const ret = await generalHttp("/system/user/getGoogleAuth", body)
		return ret
	}
	const getUserDetailInfo = async (body: object | undefined) => {
		const ret = await generalHttp("/system/user/getUserDetailInfo", body)
		return ret
	}
	return {
		getUserDetailInfo,
		getGoogleAuth,
		queryRoleList,
		staffManageList,
		updateStaffManage,
		addStaffManage,
		deleteStaffManage,
		getRolePermissionListAPI,
		getQueryPermissionList,
		roleManageList,
		updateRoleManage,
		addRoleManage,
		deleteRoleManage,
		generalHttp,
		loading
	}
}

export default useApi
